/**
 * @file
 * @brief 玄武OS移植实现层：SOC无锁队列
 * @author
 * + 隐星魂 (Roy Sun) <xwos@xwos.tech>
 * @copyright
 * + Copyright © 2015 xwos.tech, All Rights Reserved.
 * > This Source Code Form is subject to the terms of the Mozilla Public
 * > License, v. 2.0 (the "MPL"). If a copy of the MPL was not distributed
 * > with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * >
 * > Alternatively, the contents of this file may be used under the
 * > terms of the GNU General Public License version 2 (the "GPL"), in
 * > which case the provisions of the GPL are applicable instead of the
 * > above. If you wish to allow the use of your version of this file
 * > only under the terms of the GPL and not to allow others to use your
 * > version of this file under the MPL, indicate your decision by
 * > deleting the provisions above and replace them with the notice and
 * > other provisions required by the GPL. If you do not delete the
 * > provisions above, a recipient may use your version of this file
 * > under either the MPL or the GPL.
 */

#include <xwos/standard.h>
#include <xwos/lib/lfq.h>
#include <armv8a_isa.h>

__xwbsp_code
void xwlib_lfq_push(xwlfq_a * h, xwlfq_a * n)
{
        register xwlfq_t * next;

        do {
                next = (xwlfq_t *)ldaxr(h);
                *n = (xwlfq_t)next;
        } while (stlxr(h, (xwu64_t)n));
}

__xwbsp_code
xwlfq_t * xwlib_lfq_pop(xwlfq_a * h)
{
        register xwlfq_t * top;
        register xwlfq_t * next;
        xwer_t rc;

        do {
                top = (xwlfq_t *)ldaxr(h);
                if (top) {
                        next = (xwlfq_t *)(*top);
                        rc = stlxr(h, (xwu64_t)next);
                } else {
                        break;
                }
        } while (rc);
        return top;
}
